var FriendSearch = {
	showFriendList: function() {
	    var groupUserList = GetLS("GroupUserLists");
	    var groupUserArr = new Array();
	    for(var i = 0 ; i < groupUserList.length ; i++){
	        groupUserArr.push(groupUserList[i]._id);
	    }
	    console.log(groupUserArr);
        $ajax({
            url: "/user/friendlist",
            data: {_id:CurrentUser._id},
            success: function(res) {
             console.log(res.result);
             var groups = res.result;
             var html="";  
             for(var i=0;i<groups.length;i++){
                 var phone = CurrentUser.category==30?"电话:"+groups[i].phone:"Phone:" + groups[i].phone;
                 if($.inArray(groups[i]._id,groupUserArr) == -1){
                      html=html+'<div class="ub up_list detailEvt" ontouchstart="zy_touch()" >'+
                       '<div class="uw3 uh3 ub_img_cover detailEvt" style="background-image:url(\'../img/foreign.png\')"></div>'+
                        '<div class="ub-f1 ub ub-ver upl_p5">'+
                            '<div class="ub-f1 ub">'+
                                '<div class="ub-f1 ub_left">'+groups[i].name+'   '+'</div>'+
                            '</div>'+
                            '<div class="ub_left ub-f1">'+phone+'</div>'+
                        '</div>'+
                        '<div class="uw1p5 uh2p5 ub_img im_checkbox uml_1" data-id="'+groups[i]._id+'"ontouchstart="zy_touch()" onclick="FriendSearch.checkbox()"></div>'+
                    '</div>';
                 }else{
                      html=html+'<div class="ub up_list detailEvt" ontouchstart="zy_touch()" >'+
                       '<div class="uw3 uh3 ub_img_cover detailEvt" style="background-image:url(\'../img/foreign.png\')"></div>'+
                        '<div class="ub-f1 ub ub-ver upl_p5">'+
                            '<div class="ub-f1 ub">'+
                                '<div class="ub-f1 ub_left">'+groups[i].name+'   '+'</div>'+
                            '</div>'+
                            '<div class="ub_left ub-f1">'+phone+'</div>'+
                        '</div>'+
                        '<div class="uw1p5 uh2p5 ub_img im_checkbox uml_1 im_checkbox_selected_show" data-id="'+groups[i]._id+'"ontouchstart="zy_touch()"></div>'+
                    '</div>';
                 }
            
            }
              $("#ctn").html(html);
            }
        });
 
	},
	//选择好友
     checkbox:function() {
         var dom = event.currentTarget;
               if (!$(dom).hasClass("im_checkbox_selected")){
                   $(dom).addClass("im_checkbox_selected");
               }else{
                   $(dom).removeClass("im_checkbox_selected");
               }
               
       
     
    },
	//选择好友并开始群聊
	selFriendToChat:function(){
	    var addFriendFlag =GetLS("addFriendFlag");
	    var checkResults = $("#ctn .im_checkbox_selected").length;
	    if(checkResults==0){
	        if(CurrentUser.category==Role.TYPE_CHINESE){
	          $alert("请选择好友");   
	        } else {
	           $alertEn("Please choose friends");  
	        }
	       
	       return ;
	    } else{
	        var checkArrs = new Array();
               $("#ctn .im_checkbox_selected").each(function(index){
                    checkArrs.push(""+$(this).data("id"));
               });
           if(addFriendFlag=="onlyAdd"){
               var groupId = GetLS("groupchat_detail");
                $ajax({
                    url: "/group/addUserToGroup",
                    data: {
                        _id:groupId._id,
                        userid:checkArrs
                        },
                    success: function(res) {
                        (CurrentUser.category==30?$alert("添加好友成功"):$alertEn("Added your friends successfully"));
                        PCall("friendgroup_detail","Chat.groupDetailInit()");
                        PCall("friendSearchList","WinClose()");
                    }
                }); 
           }else{
               checkArrs.push(""+CurrentUser._id);
                   $ajax({
                    url: "/group/newGroupChat",
                    data: {
                        userid:CurrentUser._id,
                        friendId:checkArrs
                        },
                    success: function(res) {
                      var groups = res.result;
                      SetLS("groupchat_detail", groups);
                     OpenNewWin("groupchat_detail");   
                    }
                });
           }

	    }
	    
	    
	},//end selFriendToChat

}